package com.spring.sunflower.main.presenter;

import com.blankj.utilcode.util.LogUtils;
import com.google.gson.Gson;
import com.spring.sunflower.base.BaseObserver;
import com.spring.sunflower.base.BasePresenter;
import com.spring.sunflower.bean.RecommendAnchorsBean;
import com.spring.sunflower.bean.LabelBean;
import com.spring.sunflower.main.MainContract;

import io.reactivex.rxjava3.core.Observable;

/**
 * Created by Kevin on 2021/6/16<br/>
 * <p>
 * Describe:<br/>
 */
public class RecommendPresenter extends BasePresenter<MainContract.RecommendView> {
    private String TAG = "MainPresenter";

    public RecommendPresenter(MainContract.RecommendView baseView) {
        super(baseView);
    }

    public void getVisualizeLabel() {
        Observable<LabelBean> observable = requestDataSource.requestLabel("visualizeLabel");
        addDisposable(observable, new BaseObserver<LabelBean>(baseView) {

            @Override
            public void onSuccess(LabelBean bean) {
//                LabelBean recommendBean = handleJson(o, LabelBean.class);
                baseView.hideLoading();
                baseView.showLabelData(bean.getDatas());
            }

            @Override
            public void onError(int status, String msg) {

            }
        });
    }

    public void getRecommendAnchors(int pageIndex) {
        getRecommendAnchors(pageIndex, "");
    }

    public void getRecommendAnchors(int pageIndex, String labelId) {
        Observable<RecommendAnchorsBean> observable = requestDataSource.requestRecommendAnchors(pageIndex, labelId);
        addDisposable(observable, new BaseObserver<RecommendAnchorsBean>(baseView) {

            @Override
            public void onSuccess(RecommendAnchorsBean bean) {
                String json = new Gson().toJson(bean);
                LogUtils.dTag(TAG, "getRecommendAnchors=" + json);
//                RecommendAnchorsBean recommendAnchorsBean = (RecommendAnchorsBean) handleJson(o, RecommendAnchorsBean.class);
                String status = bean.getStatus();
                baseView.hideLoading();
//                if (status == 1) {
                baseView.showAnchorData(bean.getDatas());
//                } else {

//                }
            }

            @Override
            public void onError(int status, String msg) {

            }
        });
    }

//    public void querySignInRecord() {
//        Observable<SignInBean> observable = requestDataSource.querySignInRecord();
//        addDisposable(observable, new BaseObserver<SignInBean>() {
//            @Override
//            public void onSuccess(SignInBean bean) {
//                if (bean.getDatas() != null) {
//                    baseView.hasSigned();
//                } else {
//                    baseView.noSign();
//                }
//            }
//
//            @Override
//            public void onError(int status, String msg) {
//
//            }
//        });
//    }
//
//    public void signIn() {
//        Observable<SignInBean> observable = requestDataSource.signIn();
//        addDisposable(observable, new BaseObserver<SignInBean>() {
//            @Override
//            public void onSuccess(SignInBean bean) {
//                baseView.signSuccess(bean.getDatas());
//            }
//
//            @Override
//            public void onError(int status, String msg) {
//                baseView.signFailed(msg);
//            }
//        });
//    }
//
//    public void sayHello() {
//        Observable<HelloBean> observable = requestDataSource.sayHello();
//        addDisposable(observable, new BaseObserver<HelloBean>() {
//            @Override
//            public void onSuccess(HelloBean bean) {
//                if (bean.getDatas() != null) {
//                    baseView.sayHello(bean.getDatas());
//                } else {
//                    baseView.noSayHello();
//                }
//            }
//
//            @Override
//            public void onError(int status, String msg) {
//                baseView.signFailed(msg);
//            }
//        });
//    }
}
